
capture log close
set more off
set matsize 10000

use rep_final, clear

	*noncitizens
	keep if cit==0
	*examine ratio within cohabiting couples
	keep if related==1114

	*Define cohabiting spouse who is a citizen, out of the population
	g cohabit_cit_sp = 0
		replace cohabit_cit_sp = 1 if ((citizen_sp==2 & bpl_sp >120)  /// /*foreign born naturalized citizen*/
						  |(bpl_sp <=120 | citizen_sp==1  ))         /// /*native born or born abroad of american parents/
						  & marst>2 & citizen_sp!=. & related==1114  /*not married, cohabiting*/
	
	tab cohabit_cit_sp
	
	* Use this condition only when examining ratio within cohabiting couples
	*spouse info is avail.
	drop if citizen_sp==.

* Define control variables 

	local demog "age age2 male yreduc i.racegr"
	local imm "ysm i.bpl " 
	*cannot use yrmarr for cohabiting couples, use year
	local fe "i.statefip i.year "
	
	local full "`demog' `imm' `fe' "
	
	foreach controlgr of varlist controlgrdaca  {
							
		foreach depvar of varlist cohabit_cit_sp {
		
				
			display ""
			display "--------------------------------------"
			display "Control group: `controlgr'"
			display "Dependent Variable: `depvar' "
			
			
			display "--------------------------------------"
		
			*use ib.var to set the base year
		
			reg `depvar' ib2011.year##i.treatgr `full' if daca==1|`controlgr'==1 [pweight=perwt], cluster(statefip)	
			est sto a1

			
		esttab a1 using tableA8.csv, se replace ///
				title(Event Study) ///
				b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) nogaps 
	
		}
		
		*dep var mean
	
		sum cohabit_cit_sp [fweight=perwt] if e(sample) 	
		
	}

	
